"""
使排列满足本行大于上一行的 80% 即可
"""
dict1 = {0: 10, 1: 10, 2: 10, 3: 10, 4: 9, 5: 8, 6: 6, 7: 4}


# 第二步目标应该是
# dict1 = {'0': 10, '1': 10, '2': 9, '3': 9, '4': 9, '5': 8, '6': 6, '7': 4}


def adjust(dict1, sel_type, decrease_num, pes=0.7):
    """

    :param decrease_num: 减少的数
    :param dict1: 参数字典
    :param pes: 上下行百分比
    :return:
    """

    # 等于
    list1 = sorted(dict1.keys())
    if dict1[list1[-1]] == 0:
        dict1[list1[-1]] += 1
        decrease_num += 2
    if decrease_num % 2 != 0 and sel_type == 1:
        print(1)
        dict1[list1[0]] -= 1
        decrease_num -= 1
    elif decrease_num % 2 != 0 and sel_type == 2:
        return None
    for num in range(int(decrease_num // 2)):
        for key in list1:
            # 跳过最顶行
            if key + 1 not in dict1.keys() or key - 1 not in dict1.keys():
                continue
            elif dict1[key] - 1 <= dict1[key - 1] and dict1[key] - 1 >= dict1[key + 1]:
                dict1[key] -= 1
                break
    return dict1

# if __name__ == '__main__':
#     print(f"开始字典:{dict1}")
#     # print(f"最终结果:{adjust(dict1,0.8, 2)}")
#     print(f"最终结果:{adjust(dict1,0.9, 3)}")
